<?php
    //微信openid换取uid
    function openid2uid($openid){
        $data=M('user')->where(array('openid'=>$openid))->select();
        return $data[0]['uid'];
    }
# region 微商城首页函数
     //获取特殊状态的商品
     function state_product_list($type){
         //$type:1 新品 2 热卖 3 特价 4 首页
         $data=null;
         $newdata=null;
         switch ($type) {
             case 1:
                $data=M('products_state')->where(array('is_new'=>1))->limit(20)->select();
                break;
             case 2:
                $data=M('products_state')->where(array('is_hot'=>1))->limit(20)->select();
                break;
             case 3:
                $data=M('products_state')->where(array('is_sale'=>1))->limit(20)->select();
                break;
             default:
                $data=M('products_state')->where(array('is_index'=>1))->limit(5)->select();
                break;
         }
		 if(!empty($data))
	         for($i=0;$i<count($data);$i++){
	             $row=null;
	             if($data[$i]['parentid']==1){
	                 $row=M('hotel_room')->where(array('room_id'=>$data[$i]['pro_id']))->select();
	             }else if($data[$i]['parentid']==2){
	                 $row=M('delicacy_food')->where(array('food_id'=>$data[$i]['pro_id']))->select();
	             }else{
	                 $row=M('shop_products')->where(array('pro_id'=>$data[$i]['pro_id']))->select();
	             }
	             $newdata[$i]['parentid']=$data[$i]['parentid'];
	             $newdata[$i]['pro_id']=$data[$i]['pro_id'];
	             $newdata[$i]['pro_name']=$row[0]['title'];
	             $newdata[$i]['imgurl']=$row[0]['imgurl'];
	             $newdata[$i]['price']=$row[0]['price'];
	         }
         return $newdata;
     }
# endregion
?>